Added double-buffering to allow you to improve animation performance.
You do this by creating an image and drawing to it directly
using a Graphics object.
Double-buffering is NOT backwards compatibile --
applets that use it can't be executed by the Alpha2 release of
the HotJava browser.
You can work around this with code such as the following:
class MyApplet extends Applet {
Image im;
Graphics offscreen;
public void init() {
...
resize(400, 500); // or whatever
...
try {
im = createImage(width, height);
offscreen = new Graphics(im);
} catch (Exception e) {
// double-buffering not available
offscreen = null;
}
}
public void paintApplet(Graphics g) {
... code to paint your applet ...
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
if (offscreen != null) {
// double-buffering available
paintApplet(offscreen);
g.drawImage(im, 0, 0);
} else {
// no double-buffering
paintApplet(g);
}
}
public void destroy() {
if (offscreen != null) {
offscreen.dispose();
im.dispose();
}
}
}